using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Reader.Core;
using Chromely.Core;
using System;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
using Chromely.Core.Logging;
using Microsoft.AspNetCore;

namespace Reader
{
    class Program
    {
        internal static ReaderConfiguration config = new ReaderConfiguration();
        [STAThread]
        static void Main(string[] args)
        {
            var port = Utility.GetNotUsedPort();
            config.StartUrl = $"http://localhost:{port}";
            var appurls = new[] { $"http://localhost:{port}" };

            CreateWebHostBuilder(args)
                .UseUrls(appurls)
                .Build()
                .Start();

            AppBuilder
                .Create()
                .UseApp<ReaderApp>()
                .UseConfiguration<ReaderConfiguration>(config)
                .Build()
                .Run(args);
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
    }
}
